﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _051.文本读取和写入流
{
	internal class Program
	{
		static void Main(string[] args)
		{
			// 读取流
			string sourceFile = @"D:\VisualStudioWork\CSharp编程基础语法\051.文本读取和写入流\TextFile1.txt";
			// 1
			StreamReader reader = new StreamReader(sourceFile);
			// 2
			//FileStream fs = new FileStream(sourceFile,FileMode.Open);
			//StreamReader reader = new StreamReader(fs);
			// 3
			//FileInfo myFile	= new FileInfo(sourceFile);
			//StreamReader reader = myFile.OpenText();

			//string line = null;
			//while ((line = reader.ReadLine()) != null)
			//{
			//	Console.WriteLine(line);
			//}

			// 读完所有
			//string line = reader.ReadToEnd();
			//Console.WriteLine(line);

			// 一个字符一个字符
			//reader.Read();
			//char[] buffer = new char[1024];
			//reader.Read(buffer, 0, 1024);

			// 写入流
			//StreamWriter writer = new StreamWriter(sourceFile);
			// true表示已追加的方式写入
			StreamWriter writer = new StreamWriter(@"D:\VisualStudioWork\CSharp编程基础语法\051.文本读取和写入流\TextFile2.txt", true);
			string line = null;
			while ((line = reader.ReadLine()) != null)
			{
				writer.WriteLine(line);
			}
			writer.Close();
			reader.Close();
		}
	}
}
